package com.iwhalecloud.citybrain.flow.platform.manager.common;

import com.iwhalecloud.citybrain.flow.platform.manager.common.ErrorCode;
import org.apache.commons.lang3.StringUtils;

/**
 * @author lilh
 */
public class ErrException extends RuntimeException {

    private int errCode;
    private Object data;

    public ErrException(ErrorCode iErrCode, String message , Object data){
        super(getErrMsg(iErrCode, message));
        this.errCode = iErrCode.errCode();
        this.data = data;
    }

    public ErrException(ErrorCode iErrCode, Object data){
        super(iErrCode.errMessage());
        this.errCode = iErrCode.errCode();
        this.data = data;
    }

    public ErrException(ErrorCode iErrCode){
        super(iErrCode.errMessage());
        this.errCode = iErrCode.errCode();
    }


    public int getErrCode() {
        return errCode;
    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    private static String getErrMsg(ErrorCode iErrCode,String message){
        if(StringUtils.isEmpty(message)){
            return iErrCode.errMessage();
        }else{
            return iErrCode.errMessage().replace("{message}",message);
        }
    }
}

